package com.chen.dome9BufferedStream;

import java.io.*;

public class CopyDome1 {
    public static void main(String[] args) throws Exception {
        //目标：使用字节缓冲流完成文件的复制
        //源文件："D:\素材\图片视频素材\图片1.png"
        //目标文件：'C:\图片1.png' 必须要带文件名，因为程序无法自动生成文件名

            copy("C:\\图片1.png","D:\\图片1.png");


    }
    //复制文件

    /**
     * @param srcpath
     * @param destpath
     * @throws Exception
     */
    public static void copy(String srcpath,String destpath) throws Exception {

        try  ( InputStream src= new FileInputStream(srcpath);
               OutputStream dest=new FileOutputStream(destpath);
               InputStream src1=new BufferedInputStream(src);
               OutputStream dest1=new BufferedOutputStream(dest);) {

                byte[] bs = new byte[1024];
                int b;
                while ((b = src1.read(bs)) != -1) {// !=-1
                    dest.write(bs, 0, b);
                }
                System.out.println("复制成功");

            } catch(Exception e){
                e.printStackTrace();
            }
        }



}
